package org.testis.webautomationmodule.ui.objects;

import org.testis.data.AtofModuleConstants;
import org.testis.logging.AtofLogLevel;
import org.testis.webautomationmodule.ui.UIElementNotFoundException;
import org.testis.webautomationmodule.ui.UIElementNotVisibleException;
import org.testis.webautomationmodule.ui.UIFormFieldDecorator;

public class UILink extends UIFormFieldDecorator {

    public UILink(String id) {
        super(id);
    }

    public UILink(String id,
            String value) {
        super(id,
                value);

    }

    @Override
    protected boolean setBehavior() {
        if (!isElementPresent()) {
            String id = getId();
            setId("link=" + getId());
            if (!isElementPresent()) {
                setId("xpath=" + id);
                if (!isElementPresent()) {
                    putLog(" Link with id  is not found:" + getId(), AtofLogLevel.ERROR);
                    throw new UIElementNotVisibleException("Link   is not found:. id="
                            + getId());
                }
            }
        }
        getWebAutomationImpl().click(getId());
        putLog(" clicking link -> " + getId());
        return true;
    }

    @Override
    public boolean verifyBehavior() {
        return setBehavior();
    }

    @Override
    public boolean getBehavior() {
        return setBehavior();
    }
}

